package org.serverct.finalfight.game.hadesgame.events;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.serverct.finalfight.game.hadesgame.EventType;
import org.serverct.finalfight.internal.game.basic.BasicGame;
import org.serverct.finalfight.internal.game.hadesgame.InstantEvent;

import java.util.UUID;

public class ExchangePosition extends InstantEvent {

    public ExchangePosition(BasicGame game, EventType type) {
        super(game, type);
    }

    @Override
    public void execute() {
        Location loc = null;
        for (UUID uuid : this.game.players.keySet()) {
            Player player = Bukkit.getPlayer(uuid);
            if (!this.game.isAlive(player)) {
                continue;
            }
            if (loc == null) {
                loc = player.getLocation();
            } else {
                Location tmp = loc.clone();
                loc = player.getLocation();
                player.teleport(tmp);
            }
        }
    }
}
